package com.cmwa.solution.business.prdSetup.news.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.cmwa.solution.base.entity.Employee;
import com.cmwa.solution.base.entity.Page;
import com.cmwa.solution.base.entity.SearchParam;
import com.cmwa.solution.business.prdSetup.news.dao.NewsInfoDao;
import com.cmwa.solution.business.prdSetup.news.entity.NewsInfoCommonVo;
import com.cmwa.solution.business.prdSetup.news.entity.NewsInfoHotVo;
import com.cmwa.solution.business.prdSetup.news.service.NewsInfoService;
import com.cmwa.solution.sys.attach.service.AttachService;
import com.cmwa.solution.utils.SessionUtils;

/**
 * 通用资讯信息表业务实现层
 * 
 * @author ex-hejm
 * @date 2019-01-21 14:59:01
 */
@Service
public class NewsInfoServiceImpl implements NewsInfoService {
	@Resource
	private NewsInfoDao newsInfoDao;
	@Resource
	private AttachService attachService;
	
	public void insertNewsInfoCommon(NewsInfoCommonVo newsInfoCommon, String attIds) {
		Employee employee = SessionUtils.getEmployee();
		newsInfoCommon.setCreateId(employee.getID());
		newsInfoDao.insertNewsInfoCommon(newsInfoCommon);
		if (StringUtils.isNotEmpty(attIds)) {
			attachService.addAttachRel2(employee.getID(), newsInfoCommon.getId(), "NEWS_INFO", attIds);
		}
	}

	@Override
	public void insertNewsInfoHot(NewsInfoHotVo news, String attIds) {
		Employee employee = SessionUtils.getEmployee();
		news.setCreateId(employee.getID());
		newsInfoDao.insertNewsInfoHot(news);
		
		if (StringUtils.isNotEmpty(attIds)) {
			attachService.addAttachRel2(employee.getID(), news.getId(), "HOT_NEWS", attIds);
		}
	}
	
	public void physicDeleteNewsInfoCommonById(String id) {
		newsInfoDao.physicDeleteNewsInfoCommonById(id);
	}
	
	public void logicDeleteNewsInfoCommonById(String id) {
		newsInfoDao.logicDeleteNewsInfoCommonById(id);
	}
	
	public void updateNewsInfoCommonById(NewsInfoCommonVo newsInfoCommon) {
		newsInfoDao.updateNewsInfoCommonById(newsInfoCommon);
	}
	
	public NewsInfoCommonVo getNewsInfoCommonById(String id) {
		return newsInfoDao.getNewsInfoCommonById(id);
	}
	
	public Page<NewsInfoCommonVo> newsInfoCommonListPage(SearchParam sp) {
		List<NewsInfoCommonVo> items = newsInfoDao.newsInfoCommonListPage(sp);
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}

	@Override
	public Page<NewsInfoHotVo> newsInfoHotListPage(SearchParam sp) {
		List<NewsInfoHotVo> items = newsInfoDao.newsInfoHotListPage(sp);
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}

	@Override
	public NewsInfoHotVo getNewsInfoHotById(String id) {
		return newsInfoDao.getNewsInfoHotById(id);
	}

	@Override
	public List<NewsInfoCommonVo> homeNews() {
		return newsInfoDao.homeNews();
	}

}
